import type { RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHistory } from 'vue-router';

const routes: RouteRecordRaw[] = [
  { path: '/', redirect: '/tool/gen' },
  {
    path: '/tool',
    component: () => import('@/layout/index.vue'),
    redirect: '/tool/gen',
    children: [
      { path: '/tool/gen', name: 'CodeGen', component: () => import('@/views/gen/index.vue'), meta: { title: '代码生成' } },
      { path: '/tool/build', name: 'BuildTool', component: () => import('@/views/build/index.vue'), meta: { title: '构建工具' } },
      { path: '/tool/gen-edit/index/:tableId', name: 'GenEdit', component: () => import('@/views/gen/editTable.vue'), meta: { title: '编辑表' } },
    ]
  },
  { path: '/tool/404', name: 'NotFound', component: () => import('@/views/NotFound.vue'), meta: { title: '404' } },
  { path: '/tool/:pathMatch(.*)*', redirect: '/tool/404' },
];

const router = createRouter({
  history: createWebHistory('/'),
  routes,
  scrollBehavior: (_to, _from, savedPosition) => {
    return savedPosition || { top: 0 };
  },
});

export default router;